<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		 <div>账户余额：<span id="z1"></span></div>
		    <div>收入：<span id="s1"></span></div>
		    <div>支出：<span id="c1"></span></div>
		    <div>
		        <input placeholder="收入" id="inc">
		        <input placeholder="收入" id="inctype">
		    </div>
		    <div>
		        <input placeholder="支出" id="out">
		        <input placeholder="支出" id="outtype">
		    </div>
		    <div>
		        <input type="button" value="记录" onclick="jilu()">
		    </div>
		
		    <script>
		        var alldata = localStorage.alldata;
		        if (alldata) {
		            alldata = JSON.parse(localStorage.alldata);
		        } else {
		            alldata = {};
		            alldata.income = [];
		            alldata.fee = [];
		            alldata.total = 0;
		            alldata.totalincome = 0;
		            alldata.totalfee = 0;
		        }
		        z1.innerHTML = "￥" + alldata.total;
		        s1.innerHTML = "￥" + alldata.totalincome;
		        c1.innerHTML = "￥" + alldata.totalfee;
		
		        function jilu() {
		            if (inc.value.length > 0) {
		                var incomeobj = {
		                    money: parseFloat(inc.value),
		                    createtime: new Date().toLocaleString,
		                    label: inctype.value
		                }
		                alldata.income.unshift(incomeobj)
		            }
		            if (out.value.length > 0) {
		                var feeobj = {
		                    money: parseFloat(out.value),
		                    createtime: new Date().toLocaleString(),
		                    label: outtype.value
		                }
		                alldata.fee.unshift(feeobj)
		            }
		            
		            var totalincome = 0;
		            for (var i = 0; i < alldata.income.length; i++) {
		                totalincome += alldata.income[i].money
		            }
		            var totalfee = 0;
		            for (var i = 0; i < alldata.fee.length; i++) {
		                totalfee += alldata.fee[i].money
		            }
		            var total = totalincome - totalfee;
		            alldata.total = total;
		            alldata.totalincome = totalincome;
		            alldata.totalfee = totalfee;
		
		            z1.innerHTML = "￥" + alldata.total;
		            s1.innerHTML = "￥" + alldata.totalincome;
		            c1.innerHTML = "￥" + alldata.totalfee;
		
		            localStorage.alldata = JSON.stringify(alldata);
		            alert("记账成功！")
		        }
		
		
		
		
		    </script>
	</body>
</html>
